package com.zhongge.servlet;

import com.zhongge.entity.Student;
import com.zhongge.service.StudentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @ClassName StudentGetByIdServlet
 * @Description TODO
 * @Author zhongge
 * @Version 1.0
 */
@WebServlet("/getById")
public class StudentGetByIdServlet extends HttpServlet {
    StudentService studentService = new StudentService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取参数
        String  id = req.getParameter("searchId");
        Student student = studentService.getById(Integer.parseInt(id));
        req.setAttribute("student", student);        //转到getById.jsp中
        req.getRequestDispatcher("/student/getById.jsp").forward(req, resp);
    }
}
